package top.chenyaohua.beans;

import org.objectweb.asm.Type;
import top.chenyaohua.asm.FieldMetadata;
import top.chenyaohua.asm.MethodMetadata;

import java.util.Map;

public class RequestMapper {
    /**
     * url
     */
    private String url;
    /**
     * 方法信息
     */
    private MethodMetadata methodMetadata;
    /**
     * 类信息
     */
    private  Class<?> cls;

    /**
     * 参数class
     */
    private Class[] paramCls;

    public RequestMapper (String url, MethodMetadata methodMetadata, Class<?> cls) {
        this.url = url;
        this.methodMetadata = methodMetadata;

        Map<Integer, FieldMetadata> params = methodMetadata.getParams();
        int size = params.size();
        if (size > 0) {
            this.paramCls = new Class[size];
        }

        for (int i = 0; i < size; i++) {
            String type = params.get(i).getType();
            String className = Type.getType(type).getClassName();
            try {
               this.paramCls[i] = Class.forName(className);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }


        this.cls = cls;
    }

    public String getUrl () {
        return url;
    }

    public void setUrl (String url) {
        this.url = url;
    }

    public MethodMetadata getMethodMetadata () {
        return methodMetadata;
    }

    public void setMethodMetadata (MethodMetadata methodMetadata) {
        this.methodMetadata = methodMetadata;
    }

    public Class<?> getCls () {
        return cls;
    }

    public void setCls (Class<?> cls) {
        this.cls = cls;
    }

    public Class[] getParamCls () {
        return paramCls;
    }

    public void setParamCls (Class[] paramCls) {
        this.paramCls = paramCls;
    }
}
